//
//  LeftViewController.m
//  Deep_Breath
//
//  Created by rimi on 15/9/15.
//  Copyright (c) 2015年 LiuCong. All rights reserved.
//

#import "LeftViewController.h"
#import "gradientView.h"
#import "LoginViewController.h"
#import "ProgressBarView.h"
#import "MyJoinsViewController.h"
#import "MyCommentsViewController.h"
#import "MyCollectionViewController.h"
#import "MyTravelsViewController.h"
#import "MyActivitiesViewController.h"
#import "PersonalCenterViewController.h"
#import "SetViewController.h"

#define IMAGE_NAME(X) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:(X)]]
@interface LeftViewController ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) gradientView *gradient;
@property (nonatomic, strong) UIButton *userName;
@property (nonatomic, strong) ProgressBarView *progress;
@property (nonatomic, strong) UIView *level;
@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor colorWithRed:0.910 green:1.000 blue:0.907 alpha:1.000];
    [self initUserInterface];
}

- (void)initUserInterface {
    
//    UIImageView *customBackgournd = [[UIImageView alloc] initWithImage:IMAGE_NAME(@"个人中心背景2.jpg")];
//    customBackgournd.frame = flexibleFrame(CGRectMake(0, 0, 300, 200), NO);
//    [self.view addSubview:customBackgournd];
    
    [self.view addSubview:self.gradient];
    [self.view addSubview:self.progress];
    [self.view addSubview:self.icon];
    [self.view addSubview:self.level];
//    UIImage * image = [UIImage imageNamed:@"侧栏背景.png"];
//    UIImageView * imageView = [[UIImageView alloc] initWithImage:image];
//    imageView.frame = flexibleFrame(CGRectMake(0, 0, 300, 188), NO);
//    [self.view addSubview:imageView];
    [self.view addSubview:self.userName];
    
    NSArray * myselfNameArray = @[@"我的发起", @"我的收藏", @"我的评论", @"我的游记", @"我的加入", @"设置"];
    NSArray * imageArray = @[@"我的发起2.png", @"我的收藏2.png", @"我的评论2.png", @"我的游记2.png", @"我的加入2.png", @"设置ok.png"];
    
    for (int i = 0 ; i < 6; i ++)
    {
        UIView *line = [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(40, 270 + i * 65, 230, 1), NO)];
        line.backgroundColor = [UIColor colorWithRed:0.694 green:1.000 blue:0.769 alpha:1.000];
        [self.view addSubview:line];
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 100 + i;
        button.frame = flexibleFrame(CGRectMake(0, 210 + i * 65, 300, 60), YES);
        [button setImage:IMAGE_NAME(imageArray[i]) forState:UIControlStateNormal];
        [button setImage:IMAGE_NAME(imageArray[i]) forState:UIControlStateHighlighted];
        button.imageEdgeInsets = UIEdgeInsetsMake((SCREEN_WIDTH / WIDTH) * 19, (SCREEN_HEIGHT / HEIGHT) * 12, (SCREEN_WIDTH / WIDTH) * 16, (SCREEN_HEIGHT / HEIGHT) * 225);
        [button setTitle:myselfNameArray[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.contentEdgeInsets = UIEdgeInsetsMake(0, (SCREEN_WIDTH / WIDTH) * 40, 0, 0);
        button.titleLabel.font = [UIFont systemFontOfSize:18];
        [button addTarget:self action:@selector(handleEventUserCenter:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:flexibleFrame(CGRectMake(240, 230 + i * 65, 26, 24), NO)];
        image.image = IMAGE_NAME(@"向右箭头2.png");
        [self.view addSubview:image];
    }
}
#pragma mark -- private methods
- (void)photoTapped{
    PersonalCenterViewController *loginView = [[PersonalCenterViewController alloc] init];
    [self.navigationController pushViewController:loginView animated:YES];


}
- (void)handleEventLogin:(UIButton *)sender {
    LoginViewController *loginView = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:loginView animated:YES];

}
-(void)handleEventUserCenter:(UIButton * )sender
{
    if (sender.tag == 100)
    {
        MyActivitiesViewController *MAVC = [[MyActivitiesViewController alloc] init];
        [self.navigationController pushViewController:MAVC animated:YES];
    }
    if (sender.tag == 101)
    {
        MyCollectionViewController * selfMessageVC = [[MyCollectionViewController alloc] init];
        [self.navigationController pushViewController:selfMessageVC animated:YES];
    }if (sender.tag == 102)
    {
        MyCommentsViewController * cpVC = [[MyCommentsViewController alloc] init];
        [self.navigationController pushViewController:cpVC animated:YES];
    }if (sender.tag == 103)
    {
        MyTravelsViewController * cpVC = [[MyTravelsViewController alloc] init];
        [self.navigationController pushViewController:cpVC animated:YES];
        
    }if (sender.tag == 104)
    {
        MyJoinsViewController * aboutUsVC = [[MyJoinsViewController alloc] init];
        [self.navigationController pushViewController:aboutUsVC animated:YES];
    }
    if (sender.tag == 105) {
        SetViewController *setView = [[SetViewController alloc] init];
        [self.navigationController pushViewController:setView animated:YES];
    }
}

#pragma mark --getter

- (UIImageView *)icon {
    if (!_icon) {
        _icon = ({
            UIImageView *view = [[UIImageView alloc]initWithFrame:flexibleFrame(CGRectMake(100, 40, 100, 100), YES)];
            view.backgroundColor = [UIColor whiteColor];
            view.image = IMAGE_NAME(@"用户未登录.png");
            view.layer.cornerRadius = 50;
            view.userInteractionEnabled = YES;
            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoTapped)];
            [view addGestureRecognizer:singleTap];
            view;
        });
    }
    return _icon;
}
- (gradientView *)gradient {
    if (!_gradient) {
        _gradient = ({
            gradientView *view= [[gradientView alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 300, 667), NO)];
//            view.alpha = 0.6;
            view;
        });
    }
    return _gradient;
}

- (UIButton *)userName {
    if (!_userName) {
        _userName = ({
            UIButton *button = [[UIButton alloc] init];
            button.frame = flexibleFrame(CGRectMake(0, 0, 200, 20), NO);
            button.center = flexibleCenter(CGPointMake(300 / 2, 160));
            [button setTitle:@"点击登录" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:16];
            [button addTarget:self action:@selector(handleEventLogin:) forControlEvents:UIControlEventTouchUpInside];
            button;
        
        });
    }
    return _userName;

}


- (ProgressBarView *)progress {
    if (!_progress) {
        _progress = ({
            ProgressBarView *progressBarView = [[ProgressBarView alloc] init];
            progressBarView.frame = flexibleFrame(CGRectMake(0, 0, 104, 104), NO);
            progressBarView.center = flexibleCenter(CGPointMake(150, 90));
            [progressBarView setBackgroundColor:[UIColor colorWithRed:1.000 green:0.465 blue:0.464 alpha:0.0]];
            progressBarView.delegate = self;
            progressBarView.progressBarColor = [UIColor colorWithRed:1.000 green:0.661 blue:0.659 alpha:1.000];
            progressBarView.progressBarShadowOpacity = .1f;
            progressBarView.progressBarArcWidth = 2.0f;
            progressBarView.wrapperColor = [UIColor colorWithRed:0.200 green:0.937 blue:0.647 alpha:1.000];
            progressBarView.duration = 1.0f;
            [progressBarView run: 0.6f];
            progressBarView.layer.cornerRadius = 52;
            progressBarView.layer.shadowColor = [UIColor colorWithRed:1.000 green:0.800 blue:0.274 alpha:1.000].CGColor;//阴影颜色
            progressBarView.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
            progressBarView.layer.shadowOpacity = 1;//不透明度
            progressBarView.layer.shadowRadius = 3.0;//半径
            progressBarView;
        });
    }
    return _progress;
}

- (UIView *)level {
    if (!_level) {
        _level = ({
            UIView *label= [[UIView alloc] initWithFrame:flexibleFrame(CGRectMake(175, 115, 20, 20), NO)];
            UILabel *labellevel = [[UILabel alloc] initWithFrame:flexibleFrame(CGRectMake(0, 0, 20, 20), NO)];
            labellevel.text = @"12";
            labellevel.font = [UIFont systemFontOfSize:11];
            labellevel.textColor = [UIColor colorWithRed:0.674 green:0.337 blue:0.380 alpha:1.000];
            labellevel.textAlignment = NSTextAlignmentCenter;
            [label addSubview:labellevel];
            label.backgroundColor = [UIColor colorWithRed:1.000 green:0.902 blue:0.079 alpha:1.000];
            label.layer.cornerRadius = 10;
            label;
        });
    }
    return _level;
}














@end
